<?php
require_once('Xtras/Xtras.php');
require_once('Skeleton/Skeleton_db_cp.php');
require_once("Xtras/Classes/Class_Sessions.php");
if ($_SESSION["logged"]){
    //header("Location: index.php");
    header( "refresh:5;url=index.php" ); // Trying a 5second redirect so we can display the green message!
}
if ($_POST["login"] == "True") {
    $username = strtolower($_POST["username"]);
    $username = preg_replace("/[^a-z]/", "", $username);
    $password = $_POST["password"];
    
    $result = pg_query_params($conn, "SELECT uid FROM users WHERE login = $1 and password = $2;",array($username, $password));
    $userCheck = pg_fetch_array($result);
    if ($userCheck[0] > 0){
        $_SESSION["logged"] = TRUE;
        $_SESSION["uid"] = $userCheck[0];
        //Show that login was successful
        $login = "True";
    } else
        $login = "False";
}
?>